package com.aiowang.springboot.dynamic.activemq.starter;

import com.aiowang.springboot.dynamic.activemq.utils.DynamicActiveMQUtils;
import com.aiowang.springboot.dynamic.activemq.utils.DynamicActiveMQApplicationContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.core.JmsMessagingTemplate;

/**
 * @author aiowang
 * @date 2020-03-21 19:22
 */
@Configuration
@AutoConfigureAfter({JmsMessagingTemplate.class})
public class DynamicActivemqAutoConfigure {

    /**
     * JmsMessagingTemplate 消息模板
     */
    @Autowired
    private JmsMessagingTemplate customActivemqTemplate;

    /**
     * 注入 ActivemqUtil类
     * @return ActivemqUtil
     */
    @Bean
    @ConditionalOnMissingBean(DynamicActiveMQUtils.class)
    public DynamicActiveMQUtils getPhoneService(){
        return new DynamicActiveMQUtils(customActivemqTemplate);
    }

    /**
     * 注入DynamicActiveMQApplicationContextUtils
     * @return DynamicActiveMQApplicationContextUtils
     */
    @Bean
    @ConditionalOnMissingBean(DynamicActiveMQApplicationContextUtils.class)
    public DynamicActiveMQApplicationContextUtils getServiceFactory(){
       return new DynamicActiveMQApplicationContextUtils();
    }
}
